<script setup>
import { useRouter } from 'vue-router'
import SunComponent from '@/components/SunComponent.vue'
import GeneralButton from '@/components/GeneralButton.vue'
import WarnIcon from '@/components/icons/WarnIcon.vue'
import LadderIcon from '@/components/icons/LadderIcon.vue'
import CoinIcon from '@/components/icons/CoinIcon.vue'
import { removeLogin } from '@/utils/auth'
import { onMounted, ref } from 'vue'
import fetchCoin from '@/utils/fetchCoin'
import BackgroundImage from '@/components/BackgroundImage.vue'

const coins = ref(0)
const router = useRouter()

const logout = () => {
  removeLogin()
  router.push({ name: 'login' })
}

onMounted(async () => {
  coins.value = await fetchCoin()
})
</script>
<template>
  <div class="container">
    <background-image />
    <div class="coin">
      <coin-icon :size="64" />
      <span style="font-size: 36px; margin-left: 8px; color: white">{{ coins }}</span>
    </div>
    <sun-component class="sun" />
    <h1 class="title">跟着火车学说话</h1>
    <div class="center">
      <div class="train">
        <div class="engine-front">
          <div class="chimney">
            <div class="smoke"></div>
            <div class="smoke smoke-2"></div>
            <div class="smoke smoke-3"></div>
            <div class="smoke smoke-4"></div>
          </div>
        </div>
        <div class="engine-body"></div>
        <div class="compartment fuel-compartment">
          <warn-icon :size="48" />
          <ladder-icon :size="60" />
        </div>
        <div class="compartment wagon-compartment">
          <div class="compartment-window"></div>
        </div>
        <div class="compartment tail-compartment">
          <div class="compartment-no-window"></div>
          <div class="tail"></div>
        </div>
        <div class="wheel-holder">
          <div class="wheel"></div>
          <div class="wheel wheel-2">
            <div class="wheel-joint"></div>
            <div class="wheel-joint wheel-joint-2"></div>
          </div>
          <div class="wheel wheel-3"></div>
          <div class="wheel wheel-4"></div>
          <div class="wheel wheel-5"></div>
          <div class="wheel wheel-6"></div>
          <div class="wheel wheel-7"></div>
          <div class="wheel wheel-8"></div>
          <div class="wheel wheel-9"></div>
        </div>
      </div>
      <div class="bridge"></div>
    </div>
    <div class="buttons">
      <general-button @click="router.push({ name: 'game-select' })">
        开 始<br />游 戏 </general-button
      ><general-button @click="router.push({ name: 'data-select' })">
        数 据<br />记 录 </general-button
      ><general-button @click="logout"> 退 出<br />游 戏 </general-button>
    </div>
  </div>
</template>

<style scoped>
@import '@/styles/base-train.css';

.title {
  position: absolute;
  font-size: 144px;
  text-align: center;
  width: 100%;
  z-index: 100;
  top: 20%;
}

.sun {
  position: absolute;
  top: 10%;
  left: 20%;
}

.buttons {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

.coin {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
